import pygame
import sys
import random
import astar
from setup import *

class SnakeHead(BaseBox):
    def __init__(self,path):
        super().__init__(path[0],RED)
        self.path=path
        self.curstep=0

    def move(self):
        if self.curstep < len(self.path)-1:
            self.curstep +=1
            self.x,self.y=self.path[self.curstep]

    def get_xy(self):
        return self.x,self.y

class SnakeBody():
    def __init__(self,point,length):        
        self.bodies_xy=[]

        for _ in range(length):
            self.bodies_xy.append(point)

    def move_to(self,point):
        self.bodies_xy.insert(0,point)
        self.bodies_xy.pop()

    def add(self,point):
        self.bodies_xy.insert(0,point)


    def render(self,screen):
        for body_xy in self.bodies_xy:
            body_box=BaseBox(body_xy,BLACK)
            body_box.render(screen)

class Snake():
    def __init__(self,point,length,path):
        self.snakehead=SnakeHead(path)
        self.snakebody=SnakeBody(point,length)

    def move(self):
        self.snakehead.move()
        point=self.snakehead.get_xy()
        self.snakebody.move_to(point)

    def render(self,screen):
        
        self.snakebody.render(screen)
        self.snakehead.render(screen)
    




        






        



    

    

    